<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="onCancel"
    />
  </div>
</template>

<script>
import {editUserProfileAPI} from '@/api'

import dayjs from '@/utils/dayjs'

export default {
    model: {
        prop: 'birthday',
          event:'update:birthday'
    },
  props: {
    birthday: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      minDate: new Date(1950, 1, 1),
      maxDate: new Date(),
      currentDate: new Date(this.birthday),
    };
    },

    methods: {
        async onConfirm() {
            //1使用dayjs 格式化
            const birthday = dayjs(this.currentDate).format('YYY' - 'MM' - 'DD')
      //发送请求
            await editUserProfileAPI({
                birthday
            })
              //3修改视图
            this.$emit('index', birthday)
          //4 关闭弹层
           this.$emit('close')
            
        },
        onCancel() {
            this.$emit('close')
        },
    }
};
</script>

<style>
</style>